package com.lagou.service.impl;

import com.lagou.service.HelloService;
import org.apache.dubbo.config.annotation.Service;

import java.util.Random;
import java.util.concurrent.TimeUnit;

@Service
public class HelloServiceImpl implements HelloService {

    @Override
    public String methodA(String name, int timeToWait) {
        timeout();
        return "hello:"+name+", I'm tom";
    }

    private void timeout() {
        Random random = new Random();
        int timeout = random.nextInt(100);
        try {
            TimeUnit.MILLISECONDS.sleep(timeout);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public String methodB(String name, int timeToWait) {
        timeout();
        return "hello:"+name+", I'm jerry";
    }

    @Override
    public String methodC(String name, int timeToWait) {
        timeout();
        return "hello:"+name+", I'm lucy";
    }
}
